

#include "user_inc.h"


  
 

//初始化栈  
void ulifo_init(ulifo_t *s,uint8_t *buff,size_t size)  
{  
    s->top=0; 
    s->data =  buff;
    s->maxsize = size;
}  
  

//入栈  一个元素
int8_t ulifo_Push(ulifo_t *s,void *data,size_t len)  
{  
    
    if (s == 0)
    {
        return -1;
    }

    if (s->top + len >= s->maxsize)
    {
        return -2;
    } 

    if (len <= 0)
    {
        return -3;
    }
    
    
    memcpy(&s->data[s->top],data,len);
    s->top = s->top + len;
    
    return len;
  
}  
  
//出栈  一个元素
int8_t ulifo_Pop(ulifo_t *s,void *data,int16_t len)  
{  

    if (s == 0)
    {
        return -1;
    }

    if (s->top < len)
    {
        return -2;
    }

    if (len <= 0)
    {
        return -3;
    }
    
    s->top = s->top - (len);
    memcpy(data,&s->data[s->top],len);

    return len;
    
}   
  
//销毁栈  
void ulifo_Destroy(ulifo_t *s)  
{  
    s->top=0;  
} 





